<?php
namespace app\index\controller;
use think\Controller ;
use Db;


class Message extends Base
{
    public function index()
    {


        $list = Db::name('message')->alias('a')->field('a.*,b.msg parent_msg')
            ->join('message b','a.pid=b.id','left')
            ->order('id desc')
            ->where(['a.uid'=>$this->uid])->paginate(10);

        $img_path = config('api.oss_img_path');
        $this->assign('list',$list);
        $this->assign('img_path',$img_path);
        return $this->fetch();
    }

    //留言
    public function leaveWord(){

        $text = trim(input('text'));

        if(!$text){
          return msg(100,'请输入想要观看的电影名称');
        }
        $time = strtotime('today');

        $count = Db::name('message')->where(['uid'=>$this->uid,'pid'=>0])->count();

        if($count>=10){

            return msg(100,'今日留言次数已达上限');
        }

        $arr = array(
            'uid'=>$this->uid,
            'pid'=>0,
            'msg'=>$text,
            'create_time'=>time()
        );

        $add = Db::name('message')->insert($arr);

        if($add){
            return msg();
        }else{
            return msg(100,'保存失败');

        }
    }

}
